<?php
//require 'includes/common.inc.php';

// common.inc.php
require_once 'includes/global.func.php';
$head['title'] = $M['name'];
$head['keywords'] = $LANG['member_center'];
$head['description'] = $LANG['member_center'];
define('BUSINESSDIR', $M['url'].$M['businessdir'].'/');
require_once 'includes/output.func.php';
// common.inc.php end

//site.inc.php


// web/include/common.inc.php
//defined('IN_SITE') or exit('Access Denied');
$userid = $userid ? $userid : $id;
$r = $db->get_one("SELECT * FROM `".DB_PRE."member_company` WHERE `userid`='$userid'");
if($r)
{
	extract($r);
}

/*if(!$userid)
{
	$MS['title'] = '你要访问的站点不存在';
	$MS['description'] = '请核对网址是否正确.';
	$MS['urls'][0] = array(
		'name'=>'访问网站首页',
		'url'=>$SETTING['siteurl'],
		);
	$MS['urls'][1] = array(
		'name'=>'注册为本站会员',
		'url'=>$SETTING['siteurl'].'member/register.php',
		);
	showmessage($MS);
}*/
if(empty($tplname)) $tplname = 'default';
//用户选择的默认模板
//$companytpl_config = include WWW_ROOT.'themes/'.TPL_NAME.'/yellowpage/companytplnames.php';
$companytpl_config = include 'companytplnames.php';

$tpl = $companytpl_config[$tplname]['tplname'];

define('TPL', $tpl);
define('WEB_SKIN', 'themes/'.TPL_NAME.'/yellowpage/css/');
if($diy)
{
	define('SKIN_DIY', WEB_SKIN.$userid.'_diy.css');
}
else
{
	define('SKIN_DIY', WEB_SKIN.$companytpl_config[$tplname]['style']);
}
$menu = string2array($menu);


//$position = "<a href='$siteurl'>$system_name[index]</a> > $system_name[$category]";
if($map)
{
	$maps = explode('|',$map);
	$x = $maps[0];
	$y = $maps[1];
	$z = $maps[2];
}
include 'includes/stats.class.php';
$stats = new stats();
$vid = $_userid ? $_userid : 0;
$stats_number = $stats->get($userid,$vid);
$stats->set_userid($userid);
if($stats_number)
{
	$stats->update($stats_number['sid']);
}
else
{
	$stats->add(array('userid'=>$userid,'vid'=>$vid,'addtime'=>TIME,'updatetime'=>TIME,'ip'=>IP));
}
$banner = $banner ? $banner : 'yp/images/banner.jpg';
require_once 'includes/output.func.php';

//site.inc.php end

// job.inc.php
require_once 'includes/output.func.php';
//if(!$action) $action = 'job';
$types = subtype('yellowpage');
$template = 'job';
$catid = intval($catid);
if($head['title'])$head['title'] .= '_';
if($catid)
{
	$CSEO = cache_read('category_'.$catid.'.php');
	extract($CSEO);
	$head['title'] .= $meta_title.'_';
	$head['keywords'] = $meta_keywords.'_';
	$head['description'] = $meta_description.'_';	
}	
// job.inc.php end


// company.inc.php

// company.inc.php end


// buy.inc.php
require_once 'includes/company.class.php';
$template = 'buy';
$readproid = get_cookie('readproid');
if(intval($readproid))$prowhere = $readproid;
$catid = intval($catid);
if($head['title'])$head['title'] .= '_';
if($catid)
{
	$CSEO = cache_read('category_'.$catid.'.php');
	extract($CSEO);
	$head['title'] .= $meta_title.'_';
	$head['keywords'] = $meta_keywords.'_';
	$head['description'] = $meta_description.'_';	
}
// buy.inc.php end

// product.inc.php
require_once 'includes/company.class.php';
$readproid = get_cookie('readproid');
if(intval($readproid))$prowhere = $readproid;
$template = 'product';
$catid = intval($catid);
if($head['title'])$head['title'] .= '_';
if($catid)
{
	$CSEO = cache_read('category_'.$catid.'.php');
	extract($CSEO);
	$head['title'] .= $meta_title.'_';
	$head['keywords'] = $meta_keywords.'_';
	$head['description'] = $meta_description.'_';	
}
// product.inc.php end

// myjob.inc.php 

// myjob.inc.php end

//business/index.php
//define('IN_SITE', TRUE);
//define('ADMIN_ROOT', str_replace("\\", '/',dirname(__FILE__)).'/');
//require 'includes/common.inc.php';


session_start();

$type = $type ? $type : 'panel';
//$action = $action ? $action : $act;


$CATEGORY = subcat(NULL,'yellowpage');
//$siteurl = company_url($userid, $company_user_infos['sitedomain']);

$_SESSION['url'] = QUERY_STRING;

//if($file != 'company' && SECONDDOMAIN_ENABLE && !$company_user_infos['sitedomain']) showmessage('请先绑定您的二级域名',url("?module=$module&file=company&action=manage"));

check_priv($file);
$GROUP = cache_read('member_group.php');

//if(!@include "center/".$type.".inc.php") showmessage('The file ./center/'.$type.'.inc.php is not exists!');


function check_priv($file)
{
	global $M,$SETTING,$_groupid;
	if(!$M["allow_add_$file"]) return true;
	if(!in_array($_groupid,$M["allow_add_$file"]))
	{
		$MS['title'] = '您所在的会员组没有此项操作权限';
		$MS['description'] = '你可以做下面操作';
		$MS['urls'][0] = array(
			'name'=>'升级会员组',
			'url'=>$SETTING['siteurl'].'member/upgrade.php',
			);
		$MS['urls'][1] = array(
			'name'=>'返回商务中心',
			'url'=>'?',
			);
		msg($MS);	
	}
}

// business/index.php
switch($action){ 
	
	case 'web':
		//define('WEB_ROOT', str_replace("\\", '/',dirname(__FILE__)).'/');
		//require WEB_ROOT.'include/common.inc.php';
		
		$id = intval($id);
		if($id){
			
			
			// 原phpcms2008 web/show.php 
			include 'includes/yellowpage.class.php';
			$yellowpage = new yellowpage();
			$yellowpage->set_model($category);
			if($infos = $yellowpage->get($id))
			{
				if($infos['status']==99)
				{
					extract($infos);
					$yellowpage->hits($id);
					$head['title'] = $title.' - '.$companyname;
					$head['keywords'] = $keywords;
					$head['description'] = str_cut(strip_tags($content),200,'');
					include template('com_'.TPL.'-'.$category.'_show.html','yellowpage');
				}
				else
				{
					showmessage("该信息未通过审核");
				}
			}
			else
			{
				showmessage("该信息不存在");
			}
		}
		else{
			
			// 原phpcms2008 web/index.php 
			if(!$category) $category = 'index';
			$page = $page ? $page : 1;
			
			$head['title'] = $system_name[$category].' - '.$companyname;
			$head['keywords'] = $system_name[$category];
			$head['description'] = $system_name[$category];
			$urlrule = "$siteurl/category-$category.html|$siteurl/category-$category/page-\$page.html";
			include template('com_'.TPL.'-'.$category.'.html','yellowpage');
		}
	break;
	
	
	case 'web_query':
		if(!$category) $category = 'index';
		$page = $page ? $page : 1;
		
		$head['title'] = $companyname;
		$head['keywords'] = $system_name[$category];
		$head['description'] = $system_name[$category];
		switch($action)
		{
			case 'guestbook':
				//
			break;
			
			case 'search':
			$q = addslashes(htmlspecialchars(urldecode($q)));
			$tq = $q;
			$q = urlencode($tq);
			if($tq)$where = "AND title LIKE '%$tq%'";
			else $where = "";
			switch($type)
			{
				case 'buy':
				case 'product':
				case 'news':
				break;
				
				default:
				$type = 'product';
				break;
			}
			$category = $type;
			include template('com_'.TPL.'-search.html','yellowpage');
			break;
		}
	break;
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	case 'business':
		//
	break;
		
	
	
		
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	case 'introduce':
		$page = $page ? $page : 1;
		
		$head['title'] = $system_name[$action].' - '.$companyname;
		$head['keywords'] = $system_name[$action];
		$head['description'] = $system_name[$action];
		//$urlrule = "$siteurl/category-$category.html|$siteurl/category-$category/page-\$page.html";
		include template('yellowpage_introduce.html','yellowpage');
	break;
	
	case 'news':
		$page = $page ? $page : 1;
		
		$head['title'] = $system_name[$action].' - '.$companyname;
		$head['keywords'] = $system_name[$action];
		$head['description'] = $system_name[$action];
		include template('yellowpage_news.html','yellowpage');
	break;
	
	case 'product':
		$page = $page ? $page : 1;
		
		$head['title'] = $system_name[$action].' - '.$companyname;
		$head['keywords'] = $system_name[$action];
		$head['description'] = $system_name[$action];
		include template('yellowpage_product.html','yellowpage');
	break;
	
	case 'buy':
		$page = $page ? $page : 1;
		
		$head['title'] = $system_name[$action].' - '.$companyname;
		$head['keywords'] = $system_name[$action];
		$head['description'] = $system_name[$action];
		include template('yellowpage_buy.html','yellowpage');
	break;
	
	case 'job':
		$page = $page ? $page : 1;
		
		$head['title'] = $system_name[$action].' - '.$companyname;
		$head['keywords'] = $system_name[$action];
		$head['description'] = $system_name[$action];
		include template('yellowpage_job.html','yellowpage');
	break;
	
	case 'certificate':
		$page = $page ? $page : 1;
		
		$head['title'] = $system_name[$action].' - '.$companyname;
		$head['keywords'] = $system_name[$action];
		$head['description'] = $system_name[$action];
		include template('yellowpage_certificate.html','yellowpage');
	break;
	
	case 'guestbook':
		header("Cache-control: private");
		if($dosubmit){
			checkcode($checkcodestr,1,$forward);
			$userid = intval($userid);
			//if($userid==$_userid) showmessage('您不能给自己留言！');
			$id = intval($id);
			$qq = intval($new_qq);
			
			$username = htmlspecialchars($new_username);
			$fax = htmlspecialchars($new_fax);
			$telephone = htmlspecialchars($new_telephone);
			$unit = htmlspecialchars($new_unit);
			$msn = htmlspecialchars($new_msn);
			$email = htmlspecialchars($new_email);
			$forwardpage = htmlspecialchars($forwardpage);
			if($username=='') showmessage("用户名不能为空");
			if($telephone=='') showmessage("联系电话不能为空");
			if($unit=='') showmessage("所在单位不能为空");
	
			$db->query("INSERT INTO `".DB_PRE."yellowpage_guestbook` (`userid`, `id`, `vid`, `username`, `fax`, `telephone`, `qq`, `unit`, `msn`, `email`, `forwardpage`, `content`, `status`, `label`, `addtime`) VALUES ('$userid', '$id', '$_userid', '$username', '$fax', '$telephone', '$qq', '$unit', '$msn', '$email','$forwardpage', '$new_content', '0', '$label', '".TIME."')");
			showmessage("您的留言已经提交成功！",$forward);
		}
		else{
			$page = $page ? $page : 1;
			$head['title'] = $system_name[$action].' - '.$companyname;
			$head['keywords'] = $system_name[$action];
			$head['description'] = $system_name[$action];
			include template('yellowpage_guestbook.html','yellowpage');
		}
	break;
	
	case 'contact':
		$page = $page ? $page : 1;
		
		$head['title'] = $system_name[$action].' - '.$companyname;
		$head['keywords'] = $system_name[$action];
		$head['description'] = $system_name[$action];
		include template('yellowpage_contact.html','yellowpage');
	break;
	
	case 'qrcode':
		include template('yellowpage_qrcode.html','yellowpage');
	break;
	
	/*免费升级*/
	case 'upgrade':
		header("Cache-control: private");
		if(!$_userid) showmessage("请登录后在操作！",url("?module=member&action=login"));
		if($dosubmit){
			$company_user_infos = $db->get_one("SELECT * FROM `".DB_PRE."member_company` WHERE `userid`='$_userid'");
			if($company_user_infos)
			{
				showmessage("您已经是企业用户了",'goback');
			}
			else
			{
				$r = $db->get_one("SELECT modelid FROM `".DB_PRE."model` WHERE `tablename`='company' AND `modeltype` = 2");
				$db->query("UPDATE `".DB_PRE."member` SET modelid = '$r[modelid]' WHERE userid = '$_userid'");
				//$db->query("UPDATE `".DB_PRE."member_cache` SET modelid = '$r[modelid]' WHERE userid = '$_userid'");
				$db->query("INSERT INTO `".DB_PRE."member_company` (`userid`,`companyname`,`sitedomain`,`linkman`,`email`,`telephone`,`introduce`,`status`) VALUES ('$_userid','$companyname','$sitedomain','$linkman','$email','$telephone','$introduce',1)");
				showmessage("您已成功升级为企业会员！",url("?module=$module&file=company&action=edit"));
			}
			
			include template('register.html','yellowpage');
			cache_page(intval($M['cache_list']));
		}
		else{
			include template('register.html','yellowpage');
		}
	break;
	
	
	/*企业注册*/
	case 'register':
		if($dosubmit){
			include template('register.html','yellowpage');
			cache_page(intval($M['cache_list']));
		}
		else{
			include template('register.html','yellowpage');
		}
	break;
	
	/*服务协议*/
	case 'agreement':
		include template('agreement.html','yellowpage');
	break;
	
	/*发现企业*/
	case 'explore':
		include template('explore.html','yellowpage');
	break;
	
	
	default:
		if($userid){
			if(!$action) $action = 'index';
			$page = $page ? $page : 1;
			
			$head['title'] = /*$system_name[$action].' - '.*/$companyname;
			$head['keywords'] = $system_name[$action];
			$head['description'] = $system_name[$action];
			//$urlrule = "$siteurl/category-$category.html|$siteurl/category-$category/page-\$page.html";
			include template('yellowpage.html','yellowpage');
		}
		else{
			cache_page_start(); 
			//$CATEGORY = cache_read('category.php');
			$C = subcat(0,'yellowpage');
			$lettercat = array('a'=>NULL,'b'=>NULL,'c'=>NULL,'d'=>NULL,'e'=>NULL,'f'=>NULL,'g'=>NULL,'h'=>NULL,'i'=>NULL,'j'=>NULL,'k'=>NULL,'l'=>NULL,
			'm'=>NULL,'n'=>NULL,'o'=>NULL,'p'=>NULL,'q'=>NULL,'r'=>NULL,'s'=>NULL,'t'=>NULL,'u'=>NULL,'v'=>NULL,'w'=>NULL,'x'=>NULL,'y'=>NULL,'z'=>NULL,);
			foreach($CATEGORY as $p)
			{
				if($p['letter'] && $p['module'] == 'yp')$lettercat[$p['letter']][] = $p;
			}
			ksort($lettercat);
			$head['keywords'] = $M['name'].'_'.$M['seo_keywords'];
			$head['title'] = $M['name'].'_'.$M['seo_title'].'_'.$SETTING['sitename'];
			$head['description'] = $M['name'].'_'.$M['seo_description'].'_'.$SETTING['sitename'];
			
			include template('index.html','yellowpage');
			cache_page(intval($M['cache_index']));
		}
	break;
	
	
	
}
?>